package com.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.order.entity.ResOrderType;
import com.bhudy.enums.Relation;
import com.sys.utils.RequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bhudy.base.QueryFilter;
import com.order.service.ResOrderTypeService;

/**
 * @Author 卞洪业
 * @Description ResOrderTypeController
 * @Date Wed Feb 19 17:05:13 CST 2020
 */
@RestController
public class ResOrderTypeController {

    @Autowired
    private ResOrderTypeService resOrderTypeService;

    /**
     * 获取ResOrderType表的数据
     *
     * @param page          页数{1}
     * @param limit         显示数量{10}
     * @return ResOrderType的list
     */
    @GetMapping(value = "/api/v1/resOrderTypes")
    public Object getAll(Integer page, Integer limit){
        QueryFilter queryFilter = new QueryFilter().and("status", Relation.NOT_EQUAL, 1);
        if (page != null && limit != null) queryFilter.limit(--page, limit);
        return RequestUtils.printMapJson(0, resOrderTypeService.findList(queryFilter));
    }

    @GetMapping(value = "/api/v1/resOrderTypeJson")
    public Object resOrderTypeJson() {
        return RequestUtils.printMapJson(0, resOrderTypeService.findMapList("select res_order_type_id resOrderTypeId, type_name typeName from res_order_type where `status` != 1"));
    }

    @GetMapping(value = "/api/v1/resOrderType")
    public Object get(Long resOrderTypeId) {
        return RequestUtils.printMapJson(0, resOrderTypeService.get(resOrderTypeId));
    }

    @PostMapping(value = "/api/v1/resOrderType")
    public Object insert(@RequestBody String json) {
        return RequestUtils.printMapJson(0, resOrderTypeService.insert(JSONObject.parseObject(json, ResOrderType.class)));
    }

    @PutMapping(value = "/api/v1/resOrderType")
    public Object update(@RequestBody String json) {
        return RequestUtils.printMapJson(0, resOrderTypeService.update(JSONObject.parseObject(json, ResOrderType.class)));
    }

    @DeleteMapping(value = "/api/v1/resOrderTypes")
    public Object delete(@RequestBody String json) {
        return RequestUtils.printMapJson(0, resOrderTypeService.delete(JSONObject.parseObject(json, Long[].class)));
    }

}
